package com.dream.dao.master;

/**
 * 
 * @author Evan
 * @date 2013-8-25
 * 
 */
import java.util.List;

import org.springframework.stereotype.Repository;

import com.dream.model.master.Shop;
import com.dream.model.master.Shop.ShopType;
import com.dream.utils.hibernate.DetachedCriteriaBuilder;
import com.dream.utils.hibernate.DreamBaseDAO;
import com.dream.utils.hibernate.PagingVO;
import com.dream.vo.master.ShopVO;

@Repository
public class ShopDAO extends DreamBaseDAO<Shop> {
	
   public PagingVO query(final ShopVO vo, final PagingVO page){
		
		DetachedCriteriaBuilder queryBuilder = initQueryBuilder(vo);
		DetachedCriteriaBuilder countBuilder = initQueryBuilder(vo);
		return this.selectPagingVO(queryBuilder, page, countBuilder);
		
	}
	
	private DetachedCriteriaBuilder initQueryBuilder(final ShopVO vo){
		
		DetachedCriteriaBuilder builder = DetachedCriteriaBuilder.instance(Shop.class);
		builder.addEq("deleted", false).addLikeAny("name", vo.getName());
		builder.addIn("orgId", vo.getOrgs()).addIn("id", vo.getShops());
		builder.addEq("shopType", ShopType.getInstance(vo.getShopType()));
		return builder;
		
	}
	
	public List<Shop> queryAllWarehouse(){
		
		DetachedCriteriaBuilder builder = DetachedCriteriaBuilder.instance(Shop.class);
		builder.addEq("deleted", false).addEq("shopType", ShopType.warehouse);
		return this.select(builder);
	}
	
	
}
